package com.gec.mall.controller;

import com.gec.mall.pojo.PageReq;
import com.gec.mall.pojo.PageResp;
import com.gec.mall.pojo.RespBean;
import com.gec.mall.pojo.TbTypeTemplate;
import com.gec.mall.service.TemplateService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: li
 * @Date: 2023/2/2
 * @PACKAGE_NAME:com.gec.mall.controller
 * @Project_Name:mall-parent
 * @VERSION: 1.0.0
 */
@RestController
@RequestMapping("/template")
public class TemplateController {

    @Autowired
    private TemplateService templateService;

    @GetMapping("/getTempByPage")
    public PageResp findAllTempByPage(PageReq pageReq){
        PageHelper.startPage(pageReq.getPage(), pageReq.getSize());
        Page<TbTypeTemplate> page = (Page<TbTypeTemplate>)templateService.getAllTemplate();
        PageResp pageResp = new PageResp();
        pageResp.setTotal(page.getTotal());
        pageResp.setList(page.getResult());
        return pageResp;
    }

    @PostMapping("/saveOrUpdateTemplate")
    public RespBean tempSaveOrUpdate(@RequestBody TbTypeTemplate template){
        templateService.TemplateSaveOrUpdate(template);
        return RespBean.ok("保存成功");
    }

    @DeleteMapping("/deleteTemp/{id}")
    public RespBean tempDelByID(@PathVariable Long id){
        templateService.TemplateDelById(id);
        return RespBean.ok("删除成功");
    }
}
